﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace NDasm.Core.UI.Base
{
    public abstract class HierarchicalViewModel : ViewModel
    {
        protected readonly string scope;
        protected readonly List<HierarchicalViewModel> children;

        protected HierarchicalViewModel(string scope)
        {
            this.scope = scope;
            children = new List<HierarchicalViewModel>();
            Children = new ReadOnlyCollection<HierarchicalViewModel>(children);
        }

        public ReadOnlyCollection<HierarchicalViewModel> Children { get; private set; }
        public static event EventHandler<SelectedItemChangedEventArgs> SelectedItemChanged;

        public virtual ImageSource Glyph { get { return new BitmapImage(); } }

        private bool isExpanded;
        public bool IsExpanded
        {
            get { return isExpanded; }
            set
            {
                isExpanded = value;
                NotifyPropertyChanged(() => IsExpanded);
            }
        }

        private bool isSelected;
        public bool IsSelected
        {
            get { return isSelected; }
            set
            {
                isSelected = value;
                NotifyPropertyChanged(() => IsSelected);
                if (SelectedItemChanged != null)
                    SelectedItemChanged(this, new SelectedItemChangedEventArgs(scope, isSelected));
            }
        }
    }
}
